import unittest
import database

class DataBaseTest(unittest.TestCase):
    
    def setUp(self):
        db = database.DataBase('C:\\Users\\1\\Documents\\chto-zadali\\trunk')
        name = 'database.txt'
        self.db = db
        self.file = name
    def test_add(self):
        db = self.db
        name = self.file
        for i in range(50):
            db.add(name, str(i))
            self.assertEqual(open(name).readlines()[-1].rstrip(), str(i + 1) + '\t' + str(i))
            
    def test_get(self):
        db = self.db
        name = self.file
        for i in range(100):
            result = db.get(name, i + 1)
            if i < 50:
                self.assertEqual(int(result), i)
            else:
                self.assertEqual(result, None)
        
    def test_extract_all(self):
        db = self.db
        name = self.file
        result = db.extract_all(name)
        self.assertEqual(result, list(map(str, [i for i in range(50)])))

    #def test_delete(self):
        #db = self.db
        #name = self.file
        #for i in range(50):
            #prev_count_of_lines = len(open(name).readlines())
            #db.delete(name, i + 1)
            #new_count_of_lines = len(open(name).readlines())
            #self.assertEqual(prev_count_of_lines, new_count_of_lines + 1)
        
        
            
if __name__ == '__main__':
    unittest.main()